package bb.lanxing.util.chart;

import android.graphics.Canvas;
import android.graphics.Paint;
import com.github.mikephil.charting.animation.ChartAnimator;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.interfaces.dataprovider.LineDataProvider;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.renderer.LineChartRenderer;
import com.github.mikephil.charting.utils.Transformer;
import com.github.mikephil.charting.utils.Utils;
import com.github.mikephil.charting.utils.ViewPortHandler;
import java.util.List;

public class LineMarkerChartRender extends LineChartRenderer {
    public LineMarkerChartRender(LineDataProvider chart, ChartAnimator animator, ViewPortHandler viewPortHandler) {
        super(chart, animator, viewPortHandler);
    }

    @Override
    public void drawExtras(Canvas c) {
        int i;
        int i2;
        float[] fArr;
        super.drawExtras(c);
        List<ILineDataSet> dataSets = this.mChart.getLineData().getDataSets();
        for (int i3 = 0; i3 < dataSets.size(); i3++) {
            ILineDataSet iLineDataSet = (ILineDataSet) dataSets.get(i3);
            if ((iLineDataSet instanceof LineMarkerDataSet) && iLineDataSet.getEntryCount() > 0) {
                LineMarkerDataSet lineMarkerDataSet = (LineMarkerDataSet) iLineDataSet;
                Transformer transformer = this.mChart.getTransformer(iLineDataSet.getAxisDependency());
                float verticalPadding = lineMarkerDataSet.getVerticalPadding();
                float markerRadius = lineMarkerDataSet.getMarkerRadius();
                this.mXBounds.set(this.mChart, iLineDataSet);
                float[] fArr2 = new float[2];
                int phaseX = ((int) ((this.mXBounds.max - this.mXBounds.min) * this.mAnimator.getPhaseX())) + 1;
                int i4 = 0;
                while (i4 < phaseX) {
                    MarkerEntry entryForIndex = (MarkerEntry) iLineDataSet.getEntryForIndex(this.mXBounds.min + i4);
                    if (entryForIndex instanceof MarkerEntry) {
                        fArr2[0] = entryForIndex.getX();
                        fArr2[1] = entryForIndex.getY() * this.mAnimator.getPhaseY();
                        transformer.pointValuesToPixel(fArr2);
                        float f = fArr2[0];
                        float f2 = fArr2[1];
                        if (!this.mViewPortHandler.isInBoundsRight(f)) {
                            break;
                        } else if (this.mViewPortHandler.isInBoundsLeft(f) && this.mViewPortHandler.isInBoundsY(f2)) {
                            i = i4;
                            i2 = phaseX;
                            fArr = fArr2;
                            drawMarker(c, lineMarkerDataSet, (MarkerEntry) entryForIndex, f, f2 - verticalPadding, markerRadius);
                            i4 = i + 1;
                            fArr2 = fArr;
                            phaseX = i2;
                        }
                    }
                    i = i4;
                    i2 = phaseX;
                    fArr = fArr2;
                    i4 = i + 1;
                    fArr2 = fArr;
                    phaseX = i2;
                }
            }
        }
    }

    private void drawMarker(Canvas c, LineMarkerDataSet dataSet, MarkerEntry entry, float x, float y, float radius) {
        this.mValuePaint.setStyle(Paint.Style.FILL);
        this.mValuePaint.setColor(dataSet.getMakerColor());
        c.drawCircle(x, y, radius, this.mValuePaint);
        this.mValuePaint.setStyle(Paint.Style.FILL_AND_STROKE);
        this.mValuePaint.setColor(dataSet.getMarkerTextColor());
        this.mValuePaint.setTextSize(dataSet.getMarkerTextSize());
        c.drawText(entry.getValue(), x, y + (Utils.calcTextHeight(this.mValuePaint, "1") * 0.5f), this.mValuePaint);
    }
}
